package com.saifan.wyy_ov.common;


import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.Fragment;


import com.saifan.wyy_ov.data.bean.RoomInfoBean;



import java.util.Map;

import lomasky.ma.httpUtils.HttpUtil;
import lomasky.ma.httpUtils.ICallBack;
import lomasky.ma.httpUtils.ResponseBean;
import lomasky.ma.utils.SharedPrefUtil;



/**
 * Created by ma on 2015/5/23.
 */
public abstract class NetFragment extends BaseFragment implements ICallBack {


    public void post(String api ,Map<String, Object> params) {
        if (isNetWorkConnected(getActivity())) {
            HttpUtil.post(getActivity(), api,params,this);
        } else {
//            ToastUtil.showToast(getActivity(), "请为您的设备设置网络");
            startActivity(new Intent(Settings.ACTION_SETTINGS));
        }

    }

    public void post(String api, Map<String, Object> params, String tip) {

        if (isNetWorkConnected(getActivity())) {
            HttpUtil.post(getActivity(), api,params,tip,this);
        } else {
//            ToastUtil.showToast(getActivity(), "请为您的设备设置网络");
            startActivity(new Intent(Settings.ACTION_SETTINGS));
        }

    }


    /**
     * 检测网络是否可用
     *
     * @param context
     * @return
     */
    public boolean isNetWorkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(getActivity().CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }

        return false;
    }

    @Override
    public abstract void err(String e) ;

    @Override
    public abstract void ok(ResponseBean response) ;
}
